"use strict"
//登录与认证TOKEN
module.exports = async function () {

    let ret = await this.library.call(this, "opensdk/handle", "login");
    let data = typeof ret === 'object' ? ret : {"openid": ret};
    let opensdk = this.opensdk["_id"];

    if (!data["openid"]) {
        return this.error("opensdk id empty", opensdk);
    }
    let guid = this.opensdk["o2g"] ? data["openid"] : ret['guid'];
    let openidModel = this.model.branch("openid", this.branch);

    ret = await openidModel.login(opensdk, data["openid"], data["token"] || '', guid);

    let _isDev = 0;
    if (opensdk == 'develop') {
        _isDev = 1;
    } else {
        //查GUID
        let innerAcc = this.model.branch("innerAcc", this.branch);
        let _guid_ret = await innerAcc.find({"guid": ret['guid'], "status": {"$gte": 1}});
        if (_guid_ret) {
            _isDev = 1;
        }
    }
    ret['isDev']=_isDev;
    if (_isDev) {
        let developModel = this.model.redis("develop", this.branch);
        await developModel.set(ret['access'], 1, 600);
    }
    //是否查封账号 
    let _acc = this.model.branch("accBlock", this.branch);
    let _block_ret = await _acc.find({"openid": data["openid"]});
    if (_block_ret) {
        return this.error(_block_ret.msg, _block_ret.msg);
    }

    return ret
}